﻿using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Security;

namespace Sasa.QualityTools.CodeAnalysis.Cli
{
    [Serializable]
    public class ExecutionException : Exception
    {
        public static readonly int HasError = 0x0001;

        public static readonly int SolutionDirIsNotSpecified = 0x0002;

        public static readonly int ProjectDirIsNotSpecified = 0x0004;

        public static readonly int AssemblyPathIsNotSpecified = 0x0008;

        public static readonly int FxCopFailed = 0x0010;

        public static readonly int UnknownError = 0x8000;


        public int ErrorCode { get; private set; }


        public ExecutionException()
            : this(UnknownError, "", null)
        {
        }

        public ExecutionException(string message)
            : this(UnknownError, message, null)
        {
        }

        public ExecutionException(int errorCode, string message)
            : this(errorCode, message, null)
        {
        }

        public ExecutionException(string message, Exception innerException)
            : this(UnknownError, message, innerException)
        {
        }

        public ExecutionException(int errorCode, string message, Exception innerException)
            : base(message, innerException)
        {
            ErrorCode = HasError | errorCode;
        }

        protected ExecutionException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            ErrorCode = info.GetInt32("ErrorCode");
        }


        [SecurityCritical(SecurityCriticalScope.Everything)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("ErrorCode", ErrorCode);
        }
    }
}
